home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume4 / moveicon < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  23.2 KB

  1. Subject: tools for editing Sun icons
  2. Newsgroups: mod.sources
  3. Approved: jpn@panda.UUCP
  4.  
  5. Mod.sources:  Volume 4, Issue 119
  6. Submitted by: David C. Martin <decvax!ucbvax!dcmartin>
  7.  
  8. As you may know the Sun icon editor only edits icons of the size 64x64
  9. or 16x16.  I have written three small utility programs to edit and show
  10. icons on a terminal.
  11.  
  12. moveicon: moves a 64x64 icon in the X/Y plane (either -/-, -/+, +/-  or +/+)
  13.           and outputs an icon-style file of a 64x64 icon.
  14. trimicon: takes a 64x64 icon, trims off bits beyond the specified width and
  15.       height and outputs a width by height size icon file.
  16. showicon: shows a 64x64 icon on a terminal using x's.
  17.  
  18. There is a fourth program called showpix (still being hacked w/ from time 
  19. to time) which shows arbitrary sized pixrects on a Sun.  It takes a list 
  20. of files as arguments and opens a tool for viewing them.
  21.  
  22. Enjoy
  23.  
  24. dcm
  25. -----
  26. David C. Martin
  27. -----
  28. University of California at Berkeley
  29. College of Engineering
  30. Electronics Research Lab
  31. 434 Evans Hall
  32. Berkeley, CA 94720
  33. -----
  34. arpa: dcmartin@ingres.Berkeley.EDU                 home: 5433 Thomas Avenue
  35. uucp: {ihnp4,decvax}!ucbvax!dcmartin                     Oakland, CA 94618
  36. at&t: 415/642-3560 (O) - 415/547-8569 (H)
  37.  
  38. ------------------------- CUT HERE ---------------------------------------
  39. #! /bin/sh
  40. # This is a shell archive, meaning:
  41. # 1. Remove everything above the #! /bin/sh line.
  42. # 2. Save the resulting text in a file.
  43. # 3. Execute the file with /bin/sh (not csh) to create the files:
  44. #    Makefile
  45. #    bitmap.c
  46. #    bitmap.h
  47. #    moveicon.c
  48. #    showicon.c
  49. #    showpix.c
  50. #    showpix.icon
  51. #    trimicon.c
  52. # This archive created: Mon May 12 23:37:59 1986
  53. export PATH; PATH=/bin:$PATH
  54. echo shar: extracting "'Makefile'" '(547 characters)'
  55. if test -f 'Makefile'
  56. then
  57.     echo shar: will not over-write existing file "'Makefile'"
  58. else
  59. cat << \SHAR_EOF > 'Makefile'
  60. DEBUG    =
  61. CFLAGS    = -O $(DEBUG)
  62. AFLAGS    = -A-m68010
  63. OFILES    = showpix.o bitmap.o
  64. CC    = /bin/cc
  65. LIBS     = -lsuntool -lsunwindow -lpixrect
  66.  
  67. all:    showpix moveicon showicon trimicon
  68. showpix            : $(OFILES)
  69.             $(CC) $(CFLAGS) -o showpix $(OFILES) $(LIBS)
  70.  
  71. bitmap.o        : bitmap.c bitmap.h
  72.             $(CC) $(CFLAGS) -c bitmap.c
  73.  
  74. showpix.o        : showpix.c bitmap.h
  75.             $(CC) $(CFLAGS) -c showpix.c
  76.  
  77. moveicon        : moveicon.c
  78.             $(CC) $(CFLAGS) -o $@ moveicon.c
  79.  
  80. showicon        : showicon.c
  81.             $(CC) $(CFLAGS) -o $@ showicon.c
  82.  
  83. trimicon        : trimicon.c
  84.             $(CC) $(CFLAGS) -o $@ trimicon.c
  85. SHAR_EOF
  86. if test 547 -ne "`wc -c < 'Makefile'`"
  87. then
  88.     echo shar: error transmitting "'Makefile'" '(should have been 547 characters)'
  89. fi
  90. fi
  91. echo shar: extracting "'bitmap.c'" '(3054 characters)'
  92. if test -f 'bitmap.c'
  93. then
  94.     echo shar: will not over-write existing file "'bitmap.c'"
  95. else
  96. cat << \SHAR_EOF > 'bitmap.c'
  97. #include <stdio.h>
  98. #include <ctype.h>
  99. #include <sys/types.h>
  100. #include <sys/stat.h>
  101. #include <pixrect/pixrect_hs.h>
  102. #include "bitmap.h"
  103.  
  104. #define HEADER_FORMAT    "/* Format_version=%d, Width=%d, Height=%d, Depth=%d, \
  105.                 Valid_bits_per_item=%d"
  106.  
  107. /*
  108.  * Load bitmap header.
  109.  */
  110. extern FILE *
  111. bm_open(filename, bmh_ptr)
  112. char        *filename;
  113. Bitmap_hdr    *bmh_ptr;
  114. {
  115.     register int    c;
  116.     FILE        *fp;
  117.     char        buf[BUFSIZ];
  118.     struct stat    statbuf;
  119.  
  120.     /* stat(2) the file to make sure it is a ``regular'' file */
  121.     if (stat(filename, &statbuf) == -1) {
  122.         perror("stat");
  123.         return(NULL);
  124.     }
  125.     if (statbuf.st_mode & S_IFMT != S_IFREG) {
  126.         return(NULL);
  127.     }
  128.     /* open the file */
  129.     if ((fp = fopen(filename, "r")) == NULL) {
  130.         return(NULL);
  131.     }
  132.     /* read header information */
  133.     for (;;) {
  134.         /* get a line */
  135.         if (fgets(buf, BUFSIZ, fp) == NULL) {
  136.             (void) fclose(fp);
  137.             return(NULL);
  138.         }
  139.         /* check to see if a '=' character appears in the line */
  140.         if (index(buf, '=') == 0) continue;
  141.         /* since the '=' was present, assume this line is the format */
  142.         if (sscanf(buf, HEADER_FORMAT, &bmh_ptr->format_version, 
  143.             &bmh_ptr->width, &bmh_ptr->height, &bmh_ptr->depth, 
  144.                 &bmh_ptr->valid_bits_per_item) != 5) {
  145.             (void) fclose(fp);
  146.             return(NULL);
  147.         }
  148.         break;
  149.     } /* end for */
  150.     /* read until we get past all the comments */
  151.     while ((c = getc(fp)) != EOF && c != '\t');
  152.     /* if <c> equals EOF the file is improperly formatted */
  153.     if (c == EOF) {
  154.         (void) fclose(fp);
  155.         return(NULL);
  156.     }
  157.     /* return the file pointer */
  158.     return(fp);
  159. } /* end bm_open() */
  160.  
  161. /*
  162.  * Load specific bitmap.
  163.  */
  164. extern Bitmap *
  165. bm_load(filename)
  166. char    *filename;
  167. {
  168.     register int        i, nitem;
  169.     register u_int        *data, *data_ptr;
  170.     Bitmap            *bm_ptr;
  171.     Bitmap_hdr        bmh_buf;
  172.     FILE            *fp;
  173.  
  174.     /* open icon file and read header information */
  175.     if ((fp = bm_open(filename, &bmh_buf)) == NULL) {
  176.         return(NULL_BM);
  177.     }
  178.     /* check to make sure we still are using version 1 */
  179.     if (bmh_buf.format_version != 1) {
  180.         (void) fclose(fp);
  181.         return(NULL_BM);
  182.     }
  183.     /* compute the number of items */
  184.     nitem = ((bmh_buf.width + WORDSIZE - 1) / WORDSIZE) * bmh_buf.height;
  185.     /* create data space for bitmap */
  186.     data_ptr = data = (u_int *) malloc(sizeof(u_int) * nitem);
  187.     /* read data from file */
  188.     for (i = 0; i < nitem; i++) {
  189.         if (fscanf(fp, " 0x%X,", data_ptr++) != 1) {
  190.             free(data);
  191.             (void) fclose(fp);
  192.             return(NULL_BM);
  193.         }
  194.     }
  195.     /* create bitmap */
  196.     bm_ptr = (Bitmap *) malloc(sizeof(Bitmap));
  197.     /* initialize values */
  198.     bm_ptr->width = bmh_buf.width;
  199.     bm_ptr->height = bmh_buf.height;
  200.     bm_ptr->depth = bmh_buf.depth;
  201.     /* create bitmap pixrect */
  202.     if ((bm_ptr->bitmap_pr = mem_create(bm_ptr->width, 
  203.         bm_ptr->height, bm_ptr->depth)) == NULL) {
  204.         free(data);
  205.         free(bm_ptr);
  206.         (void) fclose(fp);
  207.         return(NULL_BM);
  208.     }
  209.     /* put data into bitmap */
  210.     data_ptr = (u_int *) mpr_d(bm_ptr->bitmap_pr)->md_image;
  211.     for (i = ((nitem % 2 == 0) ? nitem : nitem + 1); i-- > 0; i--) {
  212.         data_ptr[i / 2] = data[i];
  213.         data_ptr[i / 2] |= (data[i - 1] << WORDSIZE);
  214.     }
  215.     free(data);
  216.     (void) fclose(fp);
  217.     return(bm_ptr);
  218. } /* end bm_load() */
  219. SHAR_EOF
  220. if test 3054 -ne "`wc -c < 'bitmap.c'`"
  221. then
  222.     echo shar: error transmitting "'bitmap.c'" '(should have been 3054 characters)'
  223. fi
  224. fi
  225. echo shar: extracting "'bitmap.h'" '(401 characters)'
  226. if test -f 'bitmap.h'
  227. then
  228.     echo shar: will not over-write existing file "'bitmap.h'"
  229. else
  230. cat << \SHAR_EOF > 'bitmap.h'
  231. #ifndef BITMAP_HDR
  232. #define BITMAP_HDR
  233.  
  234. #define    WORDSIZE    16
  235.  
  236. typedef struct bitmapStruct {
  237.     int        height;
  238.     int        width;
  239.     int        depth;
  240.     struct pixrect    *bitmap_pr;
  241. } Bitmap;
  242.  
  243. typedef struct bitmap_hdrStruct {
  244.     int        depth;
  245.     int        height;
  246.     int        format_version;
  247.     int        valid_bits_per_item;
  248.     int        width;
  249. } Bitmap_hdr;
  250.  
  251. #define    NULL_BM        ((Bitmap *) NULL)
  252.  
  253. extern FILE    *bm_open();
  254. extern Bitmap    *bm_load();
  255.  
  256. #endif
  257. SHAR_EOF
  258. if test 401 -ne "`wc -c < 'bitmap.h'`"
  259. then
  260.     echo shar: error transmitting "'bitmap.h'" '(should have been 401 characters)'
  261. fi
  262. fi
  263. echo shar: extracting "'moveicon.c'" '(3878 characters)'
  264. if test -f 'moveicon.c'
  265. then
  266.     echo shar: will not over-write existing file "'moveicon.c'"
  267. else
  268. cat << \SHAR_EOF > 'moveicon.c'
  269. #include <stdio.h>
  270. #include <sys/types.h>
  271.  
  272. #define WIDTH        64
  273. #define HEIGHT        64
  274. #define WORDSIZ        16
  275. #define NCOL        (WIDTH / WORDSIZ)
  276. #define NROW        (HEIGHT)
  277.  
  278. main(argc, argv)
  279. int    argc;
  280. char    **argv;
  281. {
  282.     register int    i, j, k;
  283.     register char    c;
  284.     int        off_x, off_y;
  285.     u_int        data[NROW][NCOL];
  286.     FILE        *fp;
  287.  
  288.     /* check to make sure they specified the correct # of args */
  289.     if (argc != 3 && argc != 4) {
  290.         fprintf(stderr, "usage: moveicon offset_x offset_y { icon }\n");
  291.         exit(1);
  292.     }
  293.     /* get the offset */
  294.     off_x = atoi(argv[1]);
  295.     off_y = atoi(argv[2]);
  296.     /* did they specify a filename? */
  297.     if (argc == 4 && argv[3] != (char *) NULL) {
  298.         /* yes -- open it */
  299.         if ((fp = fopen(argv[3], "r")) == NULL) {
  300.             fprintf(stderr, "Can't open file %s for reading\n", 
  301.                 argv[3]);
  302.             exit(1);
  303.         }
  304.     } else {
  305.         /* no -- set <fp> to be stdin */
  306.         fp = stdin;
  307.     }
  308.         
  309.     /* skip the comments */
  310.     while ((c = getc(fp)) != '\t');
  311.  
  312.     /* read in the icon */
  313.     for (i = 0; i < NROW; i++) {
  314.         for (j = 0; j < NCOL; j++) {
  315.             if (fscanf(fp, " 0x%x,", &data[i][j]) != 1) {
  316.                 fprintf("Error reading file %s\n", argv[3]);
  317.                 exit(1);
  318.             }
  319.         } /* end for */
  320.     } /* end for */
  321.  
  322.     /* close the file */
  323.     fclose(fp);
  324.  
  325.     /* move the icon vertically */
  326.     if (off_y < 0) {
  327.         for (i = 0; i < NROW; i++) {
  328.             if (i - off_y < NROW) {
  329.                 for (j = 0; j < NCOL; j++) {
  330.                     data[i][j] = data[i - off_y][j];
  331.                 } /* end for */
  332.             } else {
  333.                 for (j = 0; j < NCOL; j++) {
  334.                     data[i][j] = (u_int) 0;
  335.                 } /* end for */
  336.             } /* end else */
  337.         } /* end for */
  338.     } else {
  339.         for (i = NROW - 1; i >= 0; i--) {
  340.             if (i - off_y >= 0) {
  341.                 for (j = 0; j < NCOL; j++) {
  342.                     data[i][j] = data[i - off_y][j];
  343.                 } /* end for */
  344.             } else {
  345.                 for (j = 0; j < NCOL; j++) {
  346.                     data[i][j] = (u_int) 0;
  347.                 } /* end for */
  348.             } /* end else */
  349.         } /* end for */
  350.     } /* end else */
  351.  
  352.     /* move the icon horizontally */
  353.     for (i = 0; i < NROW; i++) {
  354.         u_int    ofbits = 0;        /* overflow bits */
  355.         u_int    prev = 0;        /* previous overflow bits */
  356.  
  357.         if (off_x > 0) { 
  358.             /* do we need to shift words to the right? */
  359.             if (off_x >= WORDSIZ) {
  360.                 /* yes -- shift low to high */
  361.                 j = NCOL - 1;
  362.                 k = j - off_x / WORDSIZ;
  363.                 /* shift words to the right */
  364.                 while (j >= 0) {
  365.                     data[i][j] = data[i][k];
  366.                     data[i][k] = (u_int) 0;
  367.                     j--, k--;
  368.                 } /* end while */
  369.                 /* subtract the word shift from the offset */
  370.                 off_x = off_x % WORDSIZ;
  371.             } /* end if */
  372.             /* shift the bits in the words */
  373.             for (j = 0; j < NCOL; j++) {
  374.                 /* store the overflow bits */
  375.                 ofbits = data[i][j] << (WORDSIZ - off_x);
  376.                 /* set the new value */
  377.                 data[i][j] = prev | (data[i][j] >> off_x);
  378.                 /* make the current overflow bits previous */
  379.                 prev = ofbits;
  380.             } /* end for */
  381.         } else {
  382.             int    tmp_x = abs(off_x);
  383.  
  384.             /* do we need to shift words to the left? */
  385.             if (tmp_x >= 16) {
  386.                 /* yes -- shift high to low */
  387.                 j = tmp_x / WORDSIZ;
  388.                 k = 0;
  389.                 while (j < NCOL) {
  390.                     data[i][k] = data[i][j];
  391.                     data[i][j] = (u_int) 0;
  392.                     j++, k++;
  393.                 } /* end while */
  394.                 /* subtract the word shift from the offset */
  395.                 tmp_x = tmp_x % WORDSIZ;
  396.             } /* end if */
  397.             /* shift the bits in the words */
  398.             for (j = NCOL - 1; j >= 0; j--) {
  399.                 /* store the overflow bits */
  400.                 ofbits = data[i][j] >> (WORDSIZ - tmp_x);
  401.                 /* set the new value */
  402.                 data[i][j] = prev | (data[i][j] << tmp_x);
  403.                 /* make the current overflow bits previous */
  404.                 prev = ofbits;
  405.             } /* end for */
  406.         } /* end else */
  407.     } /* end for */
  408.  
  409.     /* output the icon file */
  410.     printf("/* Format_version=1, Width=%d, Height=%d, ", WIDTH, HEIGHT);
  411.     printf("Depth=1, Valid_bits_per_item=%d */", WORDSIZ);
  412.     for (i = 0; i < NROW; i++) {
  413.         /* print two rows on a line */
  414.         if (i % 2 == 0) printf("\n\t");
  415.         /* print the row */
  416.         for (j = 0; j < NCOL; j++) {
  417.             printf("0x%04x,", data[i][j] & 0xffff);
  418.         } /* end for */
  419.     } /* end for */
  420.     printf("\n");
  421. } /* end main() */
  422. SHAR_EOF
  423. if test 3878 -ne "`wc -c < 'moveicon.c'`"
  424. then
  425.     echo shar: error transmitting "'moveicon.c'" '(should have been 3878 characters)'
  426. fi
  427. fi
  428. echo shar: extracting "'showicon.c'" '(619 characters)'
  429. if test -f 'showicon.c'
  430. then
  431.     echo shar: will not over-write existing file "'showicon.c'"
  432. else
  433. cat << \SHAR_EOF > 'showicon.c'
  434. #include <stdio.h>
  435. #include <sys/types.h>
  436.  
  437. main(argc, argv)
  438. int    argc;
  439. char    **argv;
  440. {
  441.     register int    i, j, k;
  442.     register char    c;
  443.     u_int        data[256];
  444.     FILE        *fp;
  445.  
  446.     if (argc < 2) {
  447.         fp = stdin;
  448.     } else {
  449.         if ((fp = fopen(argv[1], "r")) == NULL) exit(1);
  450.     }
  451.     while ((c = getc(fp)) != '\t');
  452.     for (i = 0; i < 256; i++) {
  453.         if (fscanf(fp, " 0x%x,", &data[i]) != 1) {
  454.             exit(1);
  455.         }
  456.     }
  457.     for (i = 0; i < 256; i+= 4) {
  458.         for (j = 0; j < 4; j++) {
  459.             for (k = 15; k >= 0; k--) {
  460.                 if (data[i+j] & (1 << k)) {
  461.                     putchar('x');
  462.                 } else {
  463.                     putchar(' ');
  464.                 }
  465.             }
  466.         }
  467.         putchar('\n');
  468.     }
  469.     fclose(fp);
  470. } /* end main() */
  471. SHAR_EOF
  472. if test 619 -ne "`wc -c < 'showicon.c'`"
  473. then
  474.     echo shar: error transmitting "'showicon.c'" '(should have been 619 characters)'
  475. fi
  476. fi
  477. echo shar: extracting "'showpix.c'" '(6991 characters)'
  478. if test -f 'showpix.c'
  479. then
  480.     echo shar: will not over-write existing file "'showpix.c'"
  481. else
  482. cat << \SHAR_EOF > 'showpix.c'
  483. #include <stdio.h>
  484. #include <sys/types.h>
  485. #include <sys/stat.h>
  486. #include <suntool/sunview.h>
  487. #include <suntool/canvas.h>
  488. #include "bitmap.h"
  489.  
  490. /*
  491.  * Typedef'ing things...
  492.  */
  493. typedef struct pixrect    Pixrect;
  494.  
  495. /*
  496.  * Unique menu identifiers 
  497.  */
  498. #define FILEN            ((caddr_t) 1)
  499. #define MORE            ((caddr_t) 2)
  500. #define QUIT            ((caddr_t) 3)
  501.  
  502. #define MAX_BITMAPS        256
  503. #define NULL_PR            ((Pixrect *) NULL)
  504. #define canvas_width(canvas)    (int) window_get(canvas, CANVAS_WIDTH)
  505. #define canvas_height(canvas)    (int) window_get(canvas, CANVAS_HEIGHT)
  506.  
  507. #define NUM_ROW            5
  508. #define NUM_COLUMN        5
  509. #define ROW_GAP            10
  510. #define ROW_HEIGHT        64
  511. #define COLUMN_GAP        10
  512. #define COLUMN_WIDTH        64
  513. #define DISPLAY_MARGIN        10
  514. #define DISPLAY_WIDTH        ((COLUMN_WIDTH + COLUMN_GAP) * NUM_COLUMN)
  515. #define DISPLAY_HEIGHT        ((ROW_HEIGHT + ROW_GAP) * NUM_ROW)
  516. #define WINDOW_MARGIN        10
  517. #define WINDOW_WIDTH        (DISPLAY_WIDTH + 2 * DISPLAY_MARGIN + \
  518.                     2 * WINDOW_MARGIN)
  519. #define WINDOW_HEIGHT        (DISPLAY_HEIGHT + 2 * DISPLAY_MARGIN + \
  520.                     2 * WINDOW_MARGIN)
  521.  
  522. /*
  523.  * The tool's icon
  524.  */
  525. static short    icon_data[] = {
  526. #include "showpix.icon"
  527. };
  528. mpr_static(icon_pixrect, 64, 64, 1, icon_data);
  529.  
  530. /*
  531.  * The data for grey background
  532.  */
  533. static short    grey_data[] = {
  534.         0xAAAA,0x5555,0xAAAA,0x5555,
  535.     0xAAAA,0x5555,0xAAAA,0x5555,
  536.     0xAAAA,0x5555,0xAAAA,0x5555,
  537.     0xAAAA,0x5555,0xAAAA,0x5555
  538. };
  539.  
  540. /*
  541.  * The data for white background
  542.  */
  543. static short    white_data[] = {
  544.             0x0000, 0x0000, 0x0000, 0x0000,
  545.             0x0000, 0x0000, 0x0000, 0x0000,
  546.             0x0000, 0x0000, 0x0000, 0x0000,
  547.             0x0000, 0x0000, 0x0000, 0x0000
  548. };
  549.  
  550. /*
  551.  * Local variables
  552.  */
  553. Bitmap        *bitmaps[MAX_BITMAPS];
  554. static int    nbitmap;
  555. static Menu    menu;
  556. static int    display_width = DISPLAY_WIDTH;
  557. static int    display_height = DISPLAY_HEIGHT;
  558. static int    canvas_resized = FALSE;
  559. static int    ending_bitmap = 0;
  560. static Pixrect    *bkg_pr;
  561.  
  562. static void
  563. usage()
  564. {
  565.     printf("usage: showpix [ -grey ] bitmap1 [ bitmap2 ... ]\n");
  566.     exit(1);
  567. } /* end usage() */
  568.  
  569. static void
  570. punt(str)
  571. char    *str;
  572. {
  573.     fprintf(stderr, "%s\n", str);
  574.     exit(1);
  575. } /* end punt() */
  576.  
  577. /*
  578.  * Load all bitmaps specified on command line.
  579.  */
  580. static void
  581. load_bitmaps(argc, argv)
  582. int    argc;
  583. char    **argv;
  584. {
  585.     register int    i;
  586.     struct stat    statbuf;
  587.     Bitmap        *tmp_bitmap;
  588.  
  589.     /* process each argument */
  590.     for (i = 0, nbitmap = 0; i < argc; i++) {
  591.         /* check that this is a regular file */
  592.         stat(argv[i], &statbuf);
  593.         if (statbuf.st_mode & S_IFMT != TRUE) {
  594.             fprintf(stderr, "File %s not a plain file.\n", argv[i]);
  595.             continue;
  596.         } 
  597.         /* load the bitmap */
  598.         if ((tmp_bitmap = bm_load(argv[i])) == NULL_BM) {
  599.             fprintf(stderr, "Error loading %s\n", argv[i]);
  600.             continue;
  601.         } else {
  602.             bitmaps[nbitmap++] = tmp_bitmap;
  603.         }
  604.     } /* end for */
  605. } /* end load_bitmaps() */
  606.  
  607. /* 
  608.  * Print the bitmap pixrects into the canvas pixwin.
  609.  */
  610. static void
  611. paint_bitmaps(canvas)
  612. Canvas    canvas;
  613. {
  614.     register int    i, dst_x, dst_y, off_x;
  615.     Pixwin        *canvas_pw;
  616.     Pixrect        *canvas_mpr;
  617.  
  618.     /* initalialize canvas pixwin */
  619.     canvas_pw = canvas_pixwin(canvas);
  620.     /* get the memory pixrect */
  621.     canvas_mpr = canvas_pw->pw_prretained;
  622.     /* replicate background source pixrect over background pixwin */
  623.     pr_replrop(canvas_mpr, 0, 0, display_width, display_height, PIX_SRC, 
  624.         bkg_pr, 0, 0);
  625.     /* initialize vertical offset into memory pixrect */
  626.     dst_y = ROW_GAP;
  627.     /* copy bitmaps into memory pixrect */
  628.     for (i = ending_bitmap; i < nbitmap; ) {
  629.         if (dst_y + bitmaps[i]->height > display_height) break;
  630.         /* initialize horizontal offset into memory pixrect */
  631.         dst_x = COLUMN_GAP;
  632.         off_x = 0;
  633.         while (i < nbitmap) {
  634.                 if (dst_x + bitmaps[i]->width > display_width) break;
  635.             pr_rop(canvas_mpr, dst_x, dst_y, bitmaps[i]->width, 
  636.                 bitmaps[i]->height, PIX_SRC, 
  637.                 bitmaps[i]->bitmap_pr, 0, 0);
  638.             dst_x += (bitmaps[i]->width + COLUMN_GAP);
  639.             if (bitmaps[i]->height > off_x) {
  640.                 off_x = bitmaps[i]->height;
  641.             }
  642.             i++;
  643.         } /* end while */
  644.         dst_y += (off_x + ROW_GAP);
  645.     } /* end while */
  646.     /* refresh the screen image */
  647.     pw_write(canvas_pw, 0, 0, display_width, display_height, PIX_SRC,
  648.         canvas_mpr, 0, 0);
  649.     /* if we have hit the end, cycle around */
  650.     ending_bitmap = (i < nbitmap) ? i : 0;
  651. } /* end paint_bitmaps() */
  652.  
  653. static void
  654. canvas_resize_proc(canvas, width, height)
  655. Canvas    canvas;
  656. int    width;
  657. int    height;
  658. {
  659.     /* reset height && width */
  660.     display_height = canvas_height(canvas);
  661.     display_width = canvas_width(canvas);
  662.     /* cycle to beginning */
  663.     ending_bitmap = 0;
  664.     /* repaint the bitmaps */
  665.     paint_bitmaps(canvas);
  666. } /* end canvas_resize_proc() */
  667.  
  668. static void
  669. canvas_event_proc(canvas, eventp, arg)
  670. Canvas    canvas;
  671. Event    *eventp;
  672. caddr_t    arg;
  673. {
  674.     caddr_t    mi;    /* a menu item */
  675.  
  676.     /* handle the mouse button events */
  677.     switch(event_id(eventp)) {
  678.         case MS_LEFT:        /* handle left button events */
  679.             break;
  680.         case MS_MIDDLE:        /* handle middle button events */
  681.             break;
  682.         case MS_RIGHT:        /* handle right button events */
  683.             mi = menu_show(menu, canvas, eventp, 0);
  684.             if (mi == NULL) break;
  685.             switch (mi) {
  686.                 case FILEN:
  687.                     /* get new file name(s) */
  688.                     break;
  689.                 case MORE:
  690.                     /* show next page */
  691.                     paint_bitmaps(canvas);
  692.                     break;
  693.                 case QUIT:
  694.                     /* destroy all windows && exit */
  695.                     window_done(canvas);
  696.                     break;
  697.             } /* end switch */
  698.             break;
  699.     } /* end switch */
  700. } /* end canvas_event_proc() */
  701.  
  702. main(argc, argv)
  703. int    argc;
  704. char    **argv;
  705. {
  706.     Canvas        canvas;
  707.     Frame        base_frame;
  708.  
  709.     /* check for usage */
  710.     if (argc < 2) usage();
  711.     /* skip over the program name */
  712.     argc--;
  713.     argv++;
  714.     /* check to see what kind of background they want */
  715.     if (strcmp(*argv, "-grey") == 0) {
  716.         bkg_pr = mem_point(16, 16, 1, grey_data); 
  717.         /* skip over the background option */
  718.         argv++;
  719.         if (argc-- < 1) usage();
  720.     } else {
  721.         bkg_pr = mem_point(16, 16, 1, white_data);
  722.     }
  723.     /* create the root window */
  724.     if ((base_frame = window_create(NULL, FRAME, 
  725.         WIN_WIDTH,            WINDOW_WIDTH,
  726.         WIN_HEIGHT,            WINDOW_HEIGHT,
  727.         FRAME_SHOW_LABEL,        FALSE,
  728.         FRAME_ICON,            icon_create(ICON_IMAGE, &icon_pixrect),
  729.         0)) == NULL) {
  730.         punt("Error creating base frame.");
  731.     }
  732.     /* create its child */
  733.     if ((canvas = window_create(base_frame, CANVAS, 
  734.         CANVAS_WIDTH,        DISPLAY_WIDTH,
  735.         CANVAS_HEIGHT,        DISPLAY_HEIGHT,
  736.         CANVAS_MARGIN,        DISPLAY_MARGIN,
  737.         CANVAS_AUTO_EXPAND,        TRUE,
  738.         CANVAS_AUTO_SHRINK,        TRUE,
  739.         CANVAS_FIXED_IMAGE,        FALSE,
  740.         CANVAS_RETAINED,        TRUE,
  741.         CANVAS_RESIZE_PROC,        canvas_resize_proc,
  742.         WIN_EVENT_PROC,        canvas_event_proc,
  743.         0)) == NULL) {
  744.         punt("Error creating canvas.");
  745.     }
  746.     /* create a menu w/ the three menu items (FILEN, MORE && QUIT) */
  747.     if ((menu = menu_create(
  748.         MENU_ITEM, MENU_STRING_ITEM,     "File ...", FILEN, 0,
  749.         MENU_ITEM, MENU_STRING_ITEM,     "More", MORE, 0,
  750.         MENU_ITEM, MENU_STRING_ITEM,     "Quit", QUIT, 0,
  751.         MENU_INITIAL_SELECTION_SELECTED,    TRUE,
  752.         MENU_INITIAL_SELECTION,             MENU_SELECTED,
  753.         0)) == NULL) {
  754.         punt("Error creating menu.");
  755.     }
  756.     /* load the bitmaps */
  757.     load_bitmaps(argc, argv);
  758.     /* start the program */
  759.     window_main_loop(base_frame);
  760. } /* end main() */
  761. SHAR_EOF
  762. if test 6991 -ne "`wc -c < 'showpix.c'`"
  763. then
  764.     echo shar: error transmitting "'showpix.c'" '(should have been 6991 characters)'
  765. fi
  766. fi
  767. echo shar: extracting "'showpix.icon'" '(1933 characters)'
  768. if test -f 'showpix.icon'
  769. then
  770.     echo shar: will not over-write existing file "'showpix.icon'"
  771. else
  772. cat << \SHAR_EOF > 'showpix.icon'
  773. /* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
  774.  */
  775.     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  776.     0xC000,0x0000,0x0000,0x0003,0xC000,0x0000,0x0000,0x0003,
  777.     0xC000,0x0000,0x0000,0x0003,0xC000,0x0000,0x0000,0x0003,
  778.     0xC000,0x0000,0x0000,0x0003,0xC1FF,0xFFFF,0xFFFF,0xFF03,
  779.     0xC100,0x4000,0x0200,0x0183,0xC100,0x5E00,0x0200,0x0183,
  780.     0xC100,0x4000,0x0180,0x2183,0xC100,0x4000,0x0080,0x2183,
  781.     0xC100,0x9800,0x0100,0x2183,0xC100,0x8600,0x87E0,0x2183,
  782.     0xC101,0x0003,0x66A0,0x5183,0xC102,0x4004,0x1560,0x5183,
  783.     0xC10C,0x2008,0x0EA0,0x5183,0xC1F0,0x1030,0x0760,0x5183,
  784.     0xC102,0x0040,0x01A0,0x5183,0xC122,0x0080,0x00E0,0x5183,
  785.     0xC121,0x0300,0x0060,0x5183,0xC121,0x0400,0x0010,0x5183,
  786.     0xC120,0x0AF8,0x0FA8,0x5183,0xC100,0x12A8,0x0AA4,0x8983,
  787.     0xC100,0x02F8,0x0FA0,0x8983,0xC100,0x02A8,0x0AA0,0x8983,
  788.     0xC100,0x02F8,0x0FA0,0x8983,0xC100,0x0200,0x0020,0x8983,
  789.     0xC100,0x0203,0xF020,0x8983,0xC100,0x0202,0x1021,0x0583,
  790.     0xC100,0x0202,0x1021,0x0583,0xC100,0x0202,0x1021,0x0583,
  791.     0xC100,0x0202,0x9021,0xFD83,0xC100,0x0202,0x1020,0x2183,
  792.     0xC100,0x0202,0x1020,0x2183,0xC100,0x0202,0x1020,0x2183,
  793.     0xC1FF,0x8602,0x103F,0xFF83,0xC100,0xFBFF,0xFFE0,0x0183,
  794.     0xC100,0x0000,0x0000,0x0183,0xC1FF,0xFFFF,0xFFFF,0xFF83,
  795.     0xC0FF,0xFFFF,0xFFFF,0xFF83,0xC000,0x0000,0x0000,0x0003,
  796.     0xC000,0x0000,0x0000,0x0003,0xC000,0x000F,0xF000,0x0003,
  797.     0xC000,0x0008,0x1000,0x0003,0xC000,0x0008,0x1000,0x0003,
  798.     0xC000,0x000F,0xF000,0x0003,0xC000,0x0000,0x0000,0x0003,
  799.     0xC000,0x0000,0x0000,0x0003,0xC3EE,0x0000,0x0001,0x8003,
  800.     0xC666,0x0000,0x0001,0x8003,0xC606,0x0000,0x0000,0x0003,
  801.     0xC706,0xC3CE,0x7DC7,0x8773,0xC3C7,0x6666,0x2661,0x8363,
  802.     0xC0E6,0x6666,0xA661,0x81C3,0xC066,0x6666,0xA661,0x81C3,
  803.     0xC666,0x6663,0xE661,0x8363,0xC7CF,0x73C3,0x67C7,0xE773,
  804.     0xC000,0x0000,0x0600,0x0003,0xC000,0x0000,0x0600,0x0003,
  805.     0xC000,0x0000,0x0F00,0x0003,0xC000,0x0000,0x0000,0x0003,
  806.     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF
  807. SHAR_EOF
  808. if test 1933 -ne "`wc -c < 'showpix.icon'`"
  809. then
  810.     echo shar: error transmitting "'showpix.icon'" '(should have been 1933 characters)'
  811. fi
  812. fi
  813. echo shar: extracting "'trimicon.c'" '(2015 characters)'
  814. if test -f 'trimicon.c'
  815. then
  816.     echo shar: will not over-write existing file "'trimicon.c'"
  817. else
  818. cat << \SHAR_EOF > 'trimicon.c'
  819. #include <stdio.h>
  820. #include <sys/types.h>
  821.  
  822. #define WIDTH        64
  823. #define HEIGHT        64
  824. #define WORDSIZ        16
  825. #define NCOL        (WIDTH / WORDSIZ)
  826. #define NROW        (HEIGHT)
  827.  
  828. main(argc, argv)
  829. int    argc;
  830. char    **argv;
  831. {
  832.     register int    i, j, k;
  833.     register char    c;
  834.     int        width, height;
  835.     u_int        data[NROW][NCOL];
  836.     FILE        *fp;
  837.  
  838.     /* check to make sure they specified the correct # of args */
  839.     if (argc != 3 && argc != 4) {
  840.         fprintf(stderr, "usage: trimicon width height { icon }\n");
  841.         exit(1);
  842.     }
  843.     /* get the size */
  844.     width = abs(atoi(argv[1]));
  845.     height = abs(atoi(argv[2]));
  846.     /* did they specify a filename? */
  847.     if (argc == 4 && argv[3] != (char *) NULL) {
  848.         /* yes -- open it */
  849.         if ((fp = fopen(argv[3], "r")) == NULL) {
  850.             fprintf(stderr, "Can't open file %s for reading\n", 
  851.                 argv[3]);
  852.             exit(1);
  853.         }
  854.     } else {
  855.         /* no -- set <fp> to be stdin */
  856.         fp = stdin;
  857.     }
  858.         
  859.     /* skip the comments */
  860.     while ((c = getc(fp)) != '\t');
  861.  
  862.     /* read in the icon */
  863.     for (i = 0; i < NROW; i++) {
  864.         for (j = 0; j < NCOL; j++) {
  865.             if (fscanf(fp, " 0x%x,", &data[i][j]) != 1) {
  866.                 fprintf("Error reading file %s\n", argv[3]);
  867.                 exit(1);
  868.             }
  869.         } /* end for */
  870.     } /* end for */
  871.  
  872.     /* close the file */
  873.     fclose(fp);
  874.  
  875.     for (i = 0; i < NROW; i++) {
  876.         if (i > height) {
  877.             for (j = 0; j < NCOL; j++) {
  878.                 data[i][j] = (u_int) 0;
  879.             }
  880.         } else {
  881.             for (j = 0; j < NCOL; j++) {
  882.                 if (j * WORDSIZ > width) {
  883.                     data[i][j] = (u_int) 0;
  884.                 } else if (j == width / WORDSIZ) {
  885.                     k = width - j * WORDSIZ;
  886.                     data[i][j] = (data[i][j] >> k) << k;
  887.                 } /* end else */
  888.             } /* end for */
  889.         } /* end else */
  890.     } /* end for */
  891.  
  892.     /* output the icon file */
  893.     printf("/* Format_version=1, Width=%d, Height=%d, ", width, height);
  894.     printf("Depth=1, Valid_bits_per_item=%d */", WORDSIZ);
  895.     for (i = 0; i < height; i++) {
  896.         /* print two rows on a line */
  897.         if (i % 2 == 0) printf("\n\t");
  898.         /* print the row */
  899.         for (j = 0; j * WORDSIZ < width; j++) {
  900.             printf("0x%04x,", data[i][j] & 0xffff);
  901.         } /* end for */
  902.     } /* end for */
  903.     printf("\n");
  904. } /* end main() */
  905. SHAR_EOF
  906. if test 2015 -ne "`wc -c < 'trimicon.c'`"
  907. then
  908.     echo shar: error transmitting "'trimicon.c'" '(should have been 2015 characters)'
  909. fi
  910. fi
  911. exit 0
  912. #    End of shell archive
  913.